package com.xianyu.us.common.config;

import java.io.File;
import java.io.IOException;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 静态资源映射配置
 * @author wangshili
 *
 */
@Configuration
public class ResourceConfig implements WebMvcConfigurer{
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	try {
			String canonicalPath = new File("").getCanonicalPath();//获取项目根目录
			String parent = new File(canonicalPath).getParent();//获取上一级目录
			 registry.addResourceHandler("/images/common/**").addResourceLocations("file:"+parent+"/images/common/");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//获取项目的根路径
    }
}
